package com.swind.fast.modules.app.railway.project.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.modules.app.railway.project.entity.RailwayProjectSegment;
import com.swind.fast.modules.app.railway.project.service.IRailwayProjectSegmentService;
import com.swind.fast.modules.app.railway.project.vo.RailwayProjectSegmentVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/app/railway/project/segment")
@Slf4j
public class RailwayProjectSegmentController {

    @Autowired
    private IRailwayProjectSegmentService railwayProjectService;

    @GetMapping(value = "/list")
    public Result<?> queryPageList(RailwayProjectSegment railwayProject,
                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                      HttpServletRequest req) {

        QueryWrapper<RailwayProjectSegment> queryWrapper = QueryGenerator.initQueryWrapper(railwayProject, req.getParameterMap());
        Page<RailwayProjectSegment> page = new Page<RailwayProjectSegment>(pageNo, pageSize);
        IPage<RailwayProjectSegment> pageList = railwayProjectService.page(page, queryWrapper);

        // IPage<?> rpageList = railwayProjectService.getSegmentListPage(page, queryWrapper);

        return Result.OK(pageList);
    }

    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody RailwayProjectSegment railwayProject) {
        railwayProjectService.save(railwayProject);
        return Result.OK("添加成功！");
    }

    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody RailwayProjectSegment railwayProject) {
        railwayProjectService.updateById(railwayProject);
        return Result.OK("编辑成功!");
    }

    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id", required=true) String id) {
        railwayProjectService.removeById(id);
        return Result.OK("删除成功!");
    }
}
